package com.margo.project.security.config;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

/**
 * Spring security登录失败处理类
 * @author fangxingbang
 *
 */
@Component
public class MargoAuthenticationFailHandler implements AuthenticationFailureHandler{

	@Override
	public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
			AuthenticationException exception) throws IOException, ServletException {
		   System.out.println("登录失败");
		   response.setContentType("application/json");
		   response.setCharacterEncoding("UTF-8");
		   response.getWriter().write("{\"result\":\"fail\"}");
		   response.getWriter().flush();
		
	}

}
